<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/css/font.css">
      <link rel="stylesheet" href="/css/xadmin.css">
      <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
      <script src="/lib/layui/layui.js" charset="utf-8"></script>
      <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
  <div class="x-body">
      <form class="layui-form">
          <!--修改用户的uId-->
          <input type="hidden" name="uId" id="uId" th:value="${userInfo.uId}">
          <input type="hidden" name="url" class="image" th:value="${userInfo.userDetail.url}">
          <div class="layui-form-item">
              <label class="layui-form-label ">照片:</label>
              <div class="layui-upload">
                  <button type="button" class="layui-btn" id="test1">上传头像</button>
                  <div class="layui-upload-list" style="margin-left: 100px">
                      <img class="layui-upload-img" id="demo1" width="200" height="250" th:src="${userInfo.userDetail.url}">
                      <p id="demoText"></p>
                  </div>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="userName" class="layui-form-label">
                  <span class="x-red">*</span>登录名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="userName" name="userName" required="" lay-verify="required"
                         autocomplete="off" class="layui-input" th:value="${userInfo.userName}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label for="tel" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="tel" name="tel" required="" lay-verify="phone"
                         autocomplete="off" class="layui-input" th:value="${userInfo.userDetail.tel}" >
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="email" class="layui-form-label">
                  <span class="x-red">*</span>邮箱
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="email" name="email" required="" lay-verify="email"
                         autocomplete="off" class="layui-input" th:value="${userInfo.userDetail.email}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block">
                  <!-- 角色复选框隐藏值-->
                  <input type="hidden" name="roleId" id="roleId">

                  <ul   style="float: left" id="roleCheckBox">


                  </ul>
              </div>
          </div>

          <!--密码隐藏起来，这里不提供修改密码操作-->
          <input type="hidden" id="userPwd" name="userPwd" required="" lay-verify="userPwd"
                 autocomplete="off" class="layui-input" th:value="${userInfo.userPwd}">

          <div class="layui-form-item">
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  保存
              </button>
          </div>
      </form>
  </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){3,12}$/, '密码必须3到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("修改成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
          });
          
          
        });

        //修改的角色复选
        //选中当前修改用户的角色复选框信息
        $(function () {
            //获取要用户的id
            var uId= $("#uId").val();
            $.ajax({
                url:"/userInfo/loadMyRole",
                type:"get",
                dataType: "json",
                data:{"uId":uId},
                success: function(data) {
                    console.log(data);
                    //拼接复选框的html变量
                    var html = "";
                    //复选框选中的角色的变量
                    var rId="";
                    //通过js拼接 复选框 循环当前角色
                    for (var i = 0; i < data.roleInfoList.length; i++) {
                        var k=0;
                        for (var j = 0; j < data.myRoleList.length; j++) {
                            //判断当前用户的角色有哪些，拼接 选中当前复选框的角色 拼选中的复选框
                            if (data.roleInfoList[i].rName == data.myRoleList[j].rName) {
                                html += " <li style=\"float: left\" onclick=\"getRid()\">\ " +
                                    "<input  lay-filter=\"role\" " +
                                    "title=\"" + data.roleInfoList[i].rName + "\" " +
                                    "value=\"" + data.roleInfoList[i].rId + "\"  " +
                                    "type=\"checkbox\"  " +
                                    "name=\"roleName\" " +
                                    "lay-skin=\"primary\"" +
                                    "checked='' ></li>"
                                k++;
                                //把选中角色的id传给选中的角色的变量
                                rId+=data.roleInfoList[i].rId+",";
                            }
                        }
                        //当前用户没有的角色，复选框就不选中
                        if(k==0){
                            html += " <li style=\"float: left\"onclick=\"getRid()\">\ " +
                                "<input  lay-filter=\"role\" " +
                                "title=\"" + data.roleInfoList[i].rName + "\" " +
                                "value=\"" + data.roleInfoList[i].rId + "\"  " +
                                "type=\"checkbox\"  " +
                                "name=\"roleName\" " +
                                "lay-skin=\"primary\"" +
                                " ></li>"
                        }
                    }
                    //把拼接好的复选框 复制到id=roleCheckBox的ul标签中
                    $("#roleCheckBox").html(html);
                    //把选中的角色赋值给id=roleId的变量
                    $("#roleId").val(rId);
                }
            })
        });
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>